package com.icinfo.cloud.provider.punish.fastcase.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.icinfo.cloud.common.security.util.UserUtil;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.enums.DocumentKindEnum;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.common.utils.BaseUtil;
import com.icinfo.cloud.provider.punish.common.documentoperate.enums.DocumentStatusEnum;
import com.icinfo.cloud.provider.punish.config.enums.FastCaseMattersTemplateSourceEnum;
import com.icinfo.cloud.provider.punish.config.model.ConfigBusiParamDocumentInfo;
import com.icinfo.cloud.provider.punish.config.model.SysDepartParam;
import com.icinfo.cloud.provider.punish.config.service.IConfigBusiParamDocumentInfoService;
import com.icinfo.cloud.provider.punish.config.service.IConfigFastCaseMattersService;
import com.icinfo.cloud.provider.punish.config.service.ISysDepartParamService;
import com.icinfo.cloud.provider.punish.config.vo.ConfigFastProcedureDocumentInfoVo;
import com.icinfo.cloud.provider.punish.evideinv.dto.EvidenceDetailQueryDto;
import com.icinfo.cloud.provider.punish.evideinv.enums.EvidenceOperateTypeEnum;
import com.icinfo.cloud.provider.punish.evideinv.service.EvidenceInventoryService;
import com.icinfo.cloud.provider.punish.fastcase.dto.*;
import com.icinfo.cloud.provider.punish.fastcase.enums.FastCaseEvidenceCollectOperateButtonEnum;
import com.icinfo.cloud.provider.punish.fastcase.enums.SimpleFormTypeEnum;
import com.icinfo.cloud.provider.punish.fastcase.service.IFastCaseDocumentRecordService;
import com.icinfo.cloud.provider.punish.fastcase.service.IFastCaseFormSubmitService;
import com.icinfo.cloud.provider.punish.fastcase.vo.FastCaseEvidenceCollectInfoVo;
import com.icinfo.cloud.provider.punish.fastcase.vo.FastCaseEvidenceDetailVo;
import com.icinfo.cloud.provider.punish.fastcase.vo.FastCaseFormSubmitAddInfoVo;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.*;
import com.icinfo.cloud.provider.punish.ucase.caseregister.dto.CaseRelateDocumentInfoDto;
import com.icinfo.cloud.provider.punish.ucase.punishinform.dto.FastCaseAddInfoDto;
import com.icinfo.cloud.provider.punish.ucase.punishinform.dto.FastCaseAddInfoTemporaryDto;
import com.icinfo.cloud.xzcf.provider.member.userinfo.dto.UserDTO;
import com.icinfo.framework.mybatis.mapper.entity.Example;
import com.icinfo.framework.tools.utils.MapUtils;
import com.icinfo.framework.tools.utils.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 描述：简案快办证据采集
 *
 * @author shishengyao
 * @description
 * @date 2023/8/16
 */
@Service
public class FastCaseFormSubmitServiceImpl implements IFastCaseFormSubmitService {
    @Resource
    private ICaseMainInfoService caseMainInfoService;
    @Resource
    private ICaseOfflineDocumentRecordService caseOfflineDocumentRecordService;
    @Resource
    private ICaseRelatedDocumentRecordService caseRelatedDocumentRecordService;
    @Resource
    private ICaseDocumentRecordService caseDocumentRecordService;
    @Resource
    private CaseMainDetailInfoMapper caseMainDetailInfoMapper;
    @Resource
    private ICaseReasonMainRecordService caseReasonMainRecordService;
    @Resource
    private ICasePartiesRecordService casePartiesRecordService;
    @Resource
    private IConfigBusiParamDocumentInfoService configBusiParamDocumentInfoService;
    @Resource
    private CaseRelatedDocumentRecordMapper caseRelatedDocumentRecordMapper;
    @Resource
    private CaseOfflineDocumentRecordMapper caseOfflineDocumentRecordMapper;
    @Resource
    private CaseReasonMainRecordMapper caseReasonMainRecordMapper;
    @Resource
    private IConfigFastCaseMattersService configFastCaseMattersService;
    @Resource
    private CaseTemporaryRecordMapper caseTemporaryRecordMapper;
    @Resource
    private ICaseAppendixRecordService caseAppendixRecordService;
    @Resource
    private IFastCaseDocumentRecordService fastCaseDocumentRecordService;
    @Resource
    private CaseMainDetailAuxiliaryInfoMapper caseMainDetailAuxiliaryInfoMapper;
    @Resource
    private EvidenceInventoryService evidenceInventoryService;
    @Resource
    private ISysDepartParamService sysDepartParamService;
    @Resource
    private CaseDocumentRecordMapper caseDocumentRecordMapper;

    @Override
    public FastCaseEvidenceCollectInfoVo getEvidenceCollectInfo(String caseId) {
        FastCaseEvidenceCollectInfoVo evidenceCollectInfoVo = new FastCaseEvidenceCollectInfoVo();
        UserDTO userInfo = UserUtil.getUserInfo();
        CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByPrimaryKey(caseId);
        CaseReasonMainRecordVo caseReasonMainRecordVo = caseReasonMainRecordService.getCaseReasonRecordByCaseId(caseId);

        String listCode = caseReasonMainRecordVo.getCaseReasonCode();
        List<ConfigFastProcedureDocumentInfoVo> documentTemplateList = configFastCaseMattersService.getDocumentTemplateByListCode(userInfo.getOrgCode(), listCode, caseId);
        List<FastCaseEvidenceDetailVo> evidenceDetailList = new ArrayList<>();
        evidenceCollectInfoVo.setListCode(listCode);
        List<Map> caseEvidenceInfoList = evidenceInventoryService.getCaseEvidenceInfoList(caseId);
        for (ConfigFastProcedureDocumentInfoVo documentInfoVo : documentTemplateList) {
            //返回配置显示的证据列表
            if (Constant.STRING_1.equals(documentInfoVo.getIsShow())) {
                String documentKindCode = documentInfoVo.getDocumentKindCode();
                //返回的证据列表详情
                FastCaseEvidenceDetailVo evidenceDetailVo = new FastCaseEvidenceDetailVo();
                evidenceDetailVo.setTemplateSource(documentInfoVo.getDocumentShowName());
                BeanUtils.copyProperties(documentInfoVo, evidenceDetailVo);
                //1、查询案件关联文书
                if (documentInfoVo.getOperateButtonCodeList().contains(FastCaseEvidenceCollectOperateButtonEnum.RELATED_DOCUMENT.getCode())) {
                    List<CaseRelateDocumentInfoDto> caseRelateDocumentInfoList = caseRelatedDocumentRecordService.getCaseRelateDocumentInfoDto(caseId, documentKindCode, null);
                    evidenceDetailVo.setCaseRelateDocumentInfoList(assembleRelateDocumentInfoList(caseRelateDocumentInfoList,documentInfoVo));
                }
                //2、查询线下文书
                if (documentInfoVo.getOperateButtonCodeList().contains(FastCaseEvidenceCollectOperateButtonEnum.OFFLINE_DOCUMENT.getCode())) {
                    List<CaseOfflineDocumentRecord> caseOfflineDocumentInfoList = caseOfflineDocumentRecordService.getCaseOfflineDocumentRecordByKindCodes(caseId, Arrays.asList(documentInfoVo.getDocumentKindCode()));
                    evidenceDetailVo.setCaseOfflineDocumentInfoList(assembleOfflineDocumentInfoList(caseOfflineDocumentInfoList));
                }
                //模板来源是检查线上文书
                if (documentInfoVo.getOperateButtonCodeList().contains(FastCaseEvidenceCollectOperateButtonEnum.ONLINE_DOCUMENT.getCode())) {
                    if (FastCaseMattersTemplateSourceEnum.S01.getCode().equals(documentInfoVo.getTemplateSource())) {
                        //3、查询生成的文书
                        CaseDocumentRecordQueryDto queryDto = new CaseDocumentRecordQueryDto();
                        queryDto.setCaseId(caseId);
                        queryDto.setDocumentKindCode(documentKindCode);
                        List<CaseDocumentRecordDto> documentRecordDtoList = caseDocumentRecordService.getDocumentRecordDtoList(queryDto);
                        evidenceDetailVo.setCaseDocumentInfoList(assembleDocumentRecordList(documentRecordDtoList));
                    } else if (FastCaseMattersTemplateSourceEnum.S02.getCode().equals(documentInfoVo.getTemplateSource())) {
                        //组装证据端数据
                        evidenceDetailVo.setCaseDocumentInfoList(assembleEvidenceDocumentRecordList(caseEvidenceInfoList, documentInfoVo));
                    }
                }
                evidenceDetailList.add(evidenceDetailVo);
            }
        }
        evidenceCollectInfoVo.setEvidenceDetailList(evidenceDetailList);
        evidenceCollectInfoVo.setCaseId(caseId);
        evidenceCollectInfoVo.setSimpleCaseStage(caseMainDetailInfo.getSimpleCaseStage());
        evidenceCollectInfoVo.setSimpleFormType(caseMainDetailInfo.getSimpleFormType());
        return evidenceCollectInfoVo;
    }

    @Override
    @Transactional(rollbackFor = {Error.class, Exception.class})
    public int saveEvidenceCollectInfo(FastCaseEvidenceCollectInfoSaveDto saveDto) {
        UserDTO userInfo = UserUtil.getUserInfo();
        if (ObjectUtil.isEmpty(userInfo)) {
            throw new BusinessException("未登录或登录信息已失效");
        }
        String caseId = saveDto.getCaseId();
        CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(saveDto.getCaseId());
        List<FastCaseEvidenceDetailDto> evidenceDetailList = saveDto.getEvidenceDetailList();
        Example reasonExample = new Example(CaseReasonMainRecord.class);
        reasonExample.createCriteria().andEqualTo("caseId", saveDto.getCaseId()).andEqualTo("status", "1");
        List<CaseReasonMainRecord> caseReasonMainRecords = caseReasonMainRecordMapper.selectByExample(reasonExample);
        if (ObjectUtil.isEmpty(caseReasonMainRecords)) {
            throw new BusinessException("未找到对应案由编码");
        }
        List<CasePartiesRecordVo> casePartiesInfoList = casePartiesRecordService.getCasePartiesInfo(caseId);
        CasePartiesRecordVo partiesRecordVo = casePartiesInfoList.get(0);
        //查询参数配置
        List<ConfigFastProcedureDocumentInfoVo> documentTemplateList = configFastCaseMattersService.getDocumentTemplateByListCode(userInfo.getOrgCode(), caseReasonMainRecords.get(0).getCaseReasonCode(), caseId);
        for (ConfigFastProcedureDocumentInfoVo documentInfoVo : documentTemplateList) {
            String required = documentInfoVo.getIsRequired();
            //查询对应得证据详情
            FastCaseEvidenceDetailDto evidenceDetailVo = new FastCaseEvidenceDetailDto();
            List<FastCaseEvidenceDetailDto> fastCaseEvidenceDetailDtoList = evidenceDetailList.stream().filter(e -> documentInfoVo.getDocumentKindCode().equals(e.getDocumentKindCode())).collect(Collectors.toList());
            if (!ObjectUtils.isEmpty(fastCaseEvidenceDetailDtoList) && fastCaseEvidenceDetailDtoList.size() > 0) {
                evidenceDetailVo = fastCaseEvidenceDetailDtoList.get(0);
                evidenceDetailVo.setDocumentCatalogCode(documentInfoVo.getDocumentCatalogCode());
                evidenceDetailVo.setDocumentCatalogName(documentInfoVo.getDocumentCatalogName());
            }
            // 必填必传校验
            if (Constant.STRING_1.equals(required)) {
                if (ObjectUtil.isEmpty(evidenceDetailVo.getCaseOfflineDocumentInfoList())
                        && ObjectUtil.isEmpty(evidenceDetailVo.getCaseRelateDocumentInfoList())
                        && ObjectUtil.isEmpty(evidenceDetailVo.getCaseDocumentInfoList())) {
                    throw new BusinessException(documentInfoVo.getDocumentCatalogName() + "必填");
                }
            }
            List<String> operateButtonCodeList = documentInfoVo.getOperateButtonCodeList();
            //保存线下文书
            if (operateButtonCodeList.contains(FastCaseEvidenceCollectOperateButtonEnum.OFFLINE_DOCUMENT.getCode())) {
                saveOfflineDocument(caseMainInfo, userInfo, evidenceDetailVo, documentInfoVo);
            }
            //保存关联文书
            if (documentInfoVo.getOperateButtonCodeList().contains(FastCaseEvidenceCollectOperateButtonEnum.RELATED_DOCUMENT.getCode())) {
                saveRelateDocumentInfo(caseMainInfo, userInfo, evidenceDetailVo, partiesRecordVo, documentInfoVo);
            }
            //保存在线制作文书
            if (documentInfoVo.getOperateButtonCodeList().contains(FastCaseEvidenceCollectOperateButtonEnum.ONLINE_DOCUMENT.getCode())) {
                // 模板来源是处罚系统，模板来源是证据库无需处理
                if (FastCaseMattersTemplateSourceEnum.S01.getCode().equals(documentInfoVo.getTemplateSource())) {
                    checkOnlineDocument(evidenceDetailVo.getCaseDocumentInfoList(), evidenceDetailVo, partiesRecordVo, documentInfoVo);
                }
            }
        }
        //删除证据
        removeEvidenceByUids(saveDto.getRemoveEvidenceUids(), caseId);
        //  更新案件detail的表单状态和案件状态
        CaseMainDetailInfo updateCaseMainDetailInfo = new CaseMainDetailInfo();
        updateCaseMainDetailInfo.setCaseId(saveDto.getCaseId());
        updateCaseMainDetailInfo.setSimpleFormType(SimpleFormTypeEnum.INVESTIGATE_END.getCode());
        updateCaseMainDetailInfo.setSimpleCaseStage(Constant.STRING_2);
        return caseMainDetailInfoMapper.updateByPrimaryKeySelective(updateCaseMainDetailInfo);
    }

    @Override
    @Transactional(rollbackFor = {Error.class, Exception.class})
    public int saveEvidenceCollectInfoTemporary(FastCaseEvidenceCollectInfoSaveDto saveDto) {
        UserDTO userInfo = UserUtil.getUserInfo();
        if (ObjectUtil.isEmpty(userInfo)) {
            throw new BusinessException("未登录或登录信息已失效");
        }
        String caseId = saveDto.getCaseId();
        CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(saveDto.getCaseId());
        List<FastCaseEvidenceDetailDto> evidenceDetailList = saveDto.getEvidenceDetailList();
        Example reasonExample = new Example(CaseReasonMainRecord.class);
        reasonExample.createCriteria().andEqualTo("caseId", saveDto.getCaseId()).andEqualTo("status", "1");
        List<CaseReasonMainRecord> caseReasonMainRecords = caseReasonMainRecordMapper.selectByExample(reasonExample);

        List<CasePartiesRecordVo> casePartiesInfoList = casePartiesRecordService.getCasePartiesInfo(caseId);
        CasePartiesRecordVo partiesRecordVo = casePartiesInfoList.get(0);
        //查询参数配置
        List<ConfigFastProcedureDocumentInfoVo> documentTemplateList = configFastCaseMattersService.getDocumentTemplateByListCode(userInfo.getOrgCode(), caseReasonMainRecords.get(0).getCaseReasonCode(), caseId);
        for (ConfigFastProcedureDocumentInfoVo documentInfoVo : documentTemplateList) {
            //查询对应得证据详情
            FastCaseEvidenceDetailDto evidenceDetailVo = new FastCaseEvidenceDetailDto();
            List<FastCaseEvidenceDetailDto> fastCaseEvidenceDetailDtoList = evidenceDetailList.stream().filter(e -> documentInfoVo.getDocumentKindCode().equals(e.getDocumentKindCode())).collect(Collectors.toList());
            if (!ObjectUtils.isEmpty(fastCaseEvidenceDetailDtoList) && fastCaseEvidenceDetailDtoList.size() > 0) {
                evidenceDetailVo = fastCaseEvidenceDetailDtoList.get(0);
                evidenceDetailVo.setDocumentCatalogCode(documentInfoVo.getDocumentCatalogCode());
                evidenceDetailVo.setDocumentCatalogName(documentInfoVo.getDocumentCatalogName());
            }
            //保存线下文书
            if (documentInfoVo.getOperateButtonCodeList().contains(FastCaseEvidenceCollectOperateButtonEnum.OFFLINE_DOCUMENT.getCode())) {
                //保存线下文书
                saveOfflineDocument(caseMainInfo, userInfo, evidenceDetailVo, documentInfoVo);
            }
            //保存关联文书
            if (documentInfoVo.getOperateButtonCodeList().contains(FastCaseEvidenceCollectOperateButtonEnum.RELATED_DOCUMENT.getCode())) {
                //保存关联文书
                saveRelateDocumentInfo(caseMainInfo, userInfo, evidenceDetailVo, partiesRecordVo, documentInfoVo);
            }
            //删除线上文书
            if (FastCaseMattersTemplateSourceEnum.S01.getCode().equals(documentInfoVo.getTemplateSource())) {
                dealOnlineDocument(evidenceDetailVo.getCaseDocumentInfoList(), evidenceDetailVo, partiesRecordVo, documentInfoVo);
            }

        }
        //删除证据
        removeEvidenceByUids(saveDto.getRemoveEvidenceUids(), caseId);
        // 更新案件detail的表单状态和案件状态
        CaseMainDetailInfo updateCaseMainDetailInfo = new CaseMainDetailInfo();
        updateCaseMainDetailInfo.setCaseId(saveDto.getCaseId());
        updateCaseMainDetailInfo.setSimpleFormType(SimpleFormTypeEnum.EVIDENCE_COLLECTION.getCode());
        return caseMainDetailInfoMapper.updateByPrimaryKeySelective(updateCaseMainDetailInfo);
    }

    /**
     * 简案快办补充信息保存
     *
     * @param saveDto 保存dto
     * @return int
     * @author shishengyao
     * @date 2023/08/24
     */
    @Override
    @Transactional(rollbackFor = {Error.class, Exception.class})
    public int saveInvestigateEnd(FastCaseFormSubmitAddInfoDto saveDto) {
        //删除暂存信息
        Example example = new Example(CaseTemporaryRecord.class);
        example.createCriteria().andEqualTo("caseId", saveDto.getCaseId()).andEqualTo("documentCatalogCode", Constant.STRING_TEMP_FAST_CASE_ADD_INFO);
        caseTemporaryRecordMapper.deleteByExample(example);
        //更新宽表信息
        CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(saveDto.getCaseId());
        CaseMainDetailInfo updateCaseMainDetailInfo = new CaseMainDetailInfo();
        BeanUtils.copyProperties(saveDto, updateCaseMainDetailInfo);
        updateCaseMainDetailInfo.setIsHearing(Constant.STRING_0);
        updateCaseMainDetailInfo.setIsNeedCollectiveDiscuss(Constant.STRING_0);
        updateCaseMainDetailInfo.setCaseId(saveDto.getCaseId());
        updateCaseMainDetailInfo.setPunishBeforeInformPeriod(Integer.valueOf(saveDto.getStatementPleadTerm()));
        updateCaseMainDetailInfo.setSimpleFormType(SimpleFormTypeEnum.MERGE_APPROVAL.getCode());
        updateCaseMainDetailInfo.setInvestigationEndDate(saveDto.getInvestigationEndDate());
        updateCaseMainDetailInfo.setRelateEvidence(saveDto.getRelateEvidence());
        updateCaseMainDetailInfo.setPunishOpinion(ObjectUtil.isEmpty(saveDto.getPartyOpinion()) ? saveDto.getPunishContent() : saveDto.getPartyOpinion());
        int num = caseMainDetailInfoMapper.updateByPrimaryKeySelective(updateCaseMainDetailInfo);
        //更新补充表信息
        Example updateAuxiliaryInfoExample = new Example(CaseMainDetailAuxiliaryInfo.class);
        updateAuxiliaryInfoExample.createCriteria().andEqualTo("caseId", saveDto.getCaseId());
        CaseMainDetailAuxiliaryInfo updateAuxiliaryInfo = new CaseMainDetailAuxiliaryInfo();
        BeanUtils.copyProperties(saveDto, updateAuxiliaryInfo);
        updateAuxiliaryInfo.setIsHearing(Constant.STRING_0);
        updateAuxiliaryInfo.setCaseId(saveDto.getCaseId());
        updateAuxiliaryInfo.setPunishBeforeInformPeriod(Integer.valueOf(saveDto.getStatementPleadTerm()));
        updateAuxiliaryInfo.setRelateEvidence(saveDto.getRelateEvidence());
        updateAuxiliaryInfo.setPunishOpinion(ObjectUtil.isEmpty(saveDto.getPartyOpinion()) ? saveDto.getPunishContent() : saveDto.getPartyOpinion());
        caseMainDetailAuxiliaryInfoMapper.updateByExampleSelective(updateAuxiliaryInfo, updateAuxiliaryInfoExample);
        List<AppendixDto> list = saveDto.getAppendixList();
        if (!ObjectUtils.isEmpty(list)) {
            for (int i = 0; i < list.size(); i++) {
                CaseAppendixRecord record = new CaseAppendixRecord();
                record.setCaseId(saveDto.getCaseId());
                record.setCaseStageCode(caseMainInfo.getCaseCurrentStageCode());
                record.setCaseStageName(caseMainInfo.getCaseCurrentStageName());
                record.setAppendixUrl(saveDto.getAppendixList().get(i).getAppendixUrl());
                record.setAppendixTypeId(saveDto.getAppendixList().get(i).getAppendixTypeId());
                record.setAppendixName(saveDto.getAppendixList().get(i).getAppendixName());
                record.setCaseLinkCode(caseMainInfo.getCaseCurrentLinkCode());
                record.setCaseLinkName(caseMainInfo.getCaseCurrentLinkName());
                caseAppendixRecordService.saveCaseAppendixRecord(record);
            }
        }
        //生成4分文书
        FastCaseAddInfoDto fastCaseAddInfoDto = new FastCaseAddInfoDto();
        BeanUtils.copyProperties(saveDto, fastCaseAddInfoDto);
        fastCaseDocumentRecordService.saveFastCaseRegisterDocument(fastCaseAddInfoDto.getCaseId(), fastCaseAddInfoDto);
        return num;
    }

    /**
     * 简案快办补充信息暂存
     *
     * @param fastCaseAddInfoDto
     * @return {@link int}
     * @author liyafeng
     * @date 2023/5/6
     */
    @Override
    public int saveInvestigateEndTemporary(FastCaseFormSubmitAddInfoDto fastCaseAddInfoDto) {
        UserDTO userDTO = UserUtil.getUserInfo();
        //如果存在则更新
        Example example = new Example(CaseTemporaryRecord.class);
        example.createCriteria().andEqualTo("caseId", fastCaseAddInfoDto.getCaseId()).andEqualTo("documentCatalogCode", Constant.STRING_TEMP_FAST_CASE_ADD_INFO);
        List<CaseTemporaryRecord> caseTemporaryRecords = caseTemporaryRecordMapper.selectByExample(example);
        if (!ObjectUtils.isEmpty(caseTemporaryRecords)) {
            CaseTemporaryRecord caseTemporaryRecord = caseTemporaryRecords.get(0);
            CaseTemporaryRecord updaterecord = new CaseTemporaryRecord();
            updaterecord.setId(caseTemporaryRecord.getId());
            updaterecord.setAddUser(userDTO.getLoginName());
            updaterecord.setCreateTime(LocalDateTime.now());
            updaterecord.setContent(JSON.toJSONString(fastCaseAddInfoDto));
            return caseTemporaryRecordMapper.updateByPrimaryKeySelective(updaterecord);
        }
        CaseTemporaryRecord record = new CaseTemporaryRecord();
        record.setId(BaseUtil.createUid());
        record.setCaseId(fastCaseAddInfoDto.getCaseId());
        record.setContent(JSON.toJSONString(fastCaseAddInfoDto));
        record.setAddUser(userDTO.getLoginName());
        record.setCreateTime(LocalDateTime.now());
        record.setDocumentCatalogCode(Constant.STRING_TEMP_FAST_CASE_ADD_INFO);
        int num = caseTemporaryRecordMapper.insertSelective(record);
        return num;
    }

    /**
     * 简案快办补充信息暂存获取
     *
     * @param dto
     * @return {@link FastCaseAddInfoDto}
     * @author liyafeng
     * @date 2023/5/6
     */
    @Override
    public FastCaseFormSubmitAddInfoVo getFastCaseAddInfoTemporary(FastCaseAddInfoTemporaryDto dto) {
        FastCaseFormSubmitAddInfoVo fastCaseAddInfoDto = new FastCaseFormSubmitAddInfoVo();
        String caseId = dto.getCaseId();
        CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
        CaseReasonMainRecordVo caseReasonMainRecordVo = caseReasonMainRecordService.getCaseReasonRecordByCaseId(caseId);
        CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByPrimaryKey(caseId);
        List<CasePartiesRecordVo> casePartiesInfoList = casePartiesRecordService.getCasePartiesInfo(caseId);
        CasePartiesRecordVo casePartiesInfo = casePartiesInfoList.get(0);
        String caseHappenTime = "";
        if (ObjectUtil.isNotEmpty(caseMainDetailInfo.getCaseHappenTime())) {
            caseHappenTime = DateTimeFormatter.ofPattern("yyyy年M月d日").format(caseMainDetailInfo.getCaseHappenTime());
        }
        String listCode = caseReasonMainRecordVo.getCaseReasonCode();
        Example example = new Example(CaseTemporaryRecord.class);
        example.createCriteria().andEqualTo("caseId", dto.getCaseId()).andEqualTo("documentCatalogCode", Constant.STRING_TEMP_FAST_CASE_ADD_INFO);
        List<CaseTemporaryRecord> caseTemporaryRecords = caseTemporaryRecordMapper.selectByExample(example);
        if (!ObjectUtils.isEmpty(caseTemporaryRecords)) {
            String fastCaseAddInfoDtoStr = caseTemporaryRecords.get(Constant.INTEGER_0).getContent();
            fastCaseAddInfoDto = JSON.parseObject(fastCaseAddInfoDtoStr, FastCaseFormSubmitAddInfoVo.class);
        } else {
            BeanUtils.copyProperties(caseMainDetailInfo, fastCaseAddInfoDto);
            fastCaseAddInfoDto.setCaseId(caseId);
            fastCaseAddInfoDto.setCaseName(caseMainDetailInfo.getCaseName());
            fastCaseAddInfoDto.setCaseProceedTime(caseMainDetailInfo.getCaseProceedTime());
            fastCaseAddInfoDto.setInvestigationStartDate(caseMainDetailInfo.getInvestigationStartDate());
            fastCaseAddInfoDto.setInvestigationEndDate(caseMainDetailInfo.getInvestigationEndDate());
            fastCaseAddInfoDto.setInvestConclusion(caseMainDetailInfo.getInvestConclusion());
            fastCaseAddInfoDto.setPunishKinds(caseMainDetailInfo.getPunishKinds());
            fastCaseAddInfoDto.setDiscretionInterval(caseMainDetailInfo.getDiscretionInterval());
            fastCaseAddInfoDto.setPunishContent(caseMainDetailInfo.getPunishContent());
            fastCaseAddInfoDto.setCaseHappenProcess(caseMainDetailInfo.getCaseHappenProcess());
            String illegalFact = "当事人" + casePartiesInfo.getPartyName() + "于" + caseHappenTime + "在" + caseMainDetailInfo.getCaseHappenAddressDetail()
                    + "涉嫌" + caseReasonMainRecordVo.getCaseReasonNameSimple();
            fastCaseAddInfoDto.setIllegalFact(ObjectUtil.isEmpty(caseMainDetailInfo.getIllegalFact()) ? illegalFact : caseMainDetailInfo.getIllegalFact());
            SysDepartParam sysDepartParam = sysDepartParamService.getSysDepartParamByOrgCode(caseMainInfo.getCaseOrgCode(), caseMainInfo.getCaseDeptCode());
            fastCaseAddInfoDto.setFastTelephone(ObjectUtil.isEmpty(caseMainDetailInfo.getFastTelephone()) ? sysDepartParam.getPhone() : caseMainDetailInfo.getFastTelephone());
            fastCaseAddInfoDto.setFastContactAddress(ObjectUtil.isEmpty(caseMainDetailInfo.getFastContactAddress()) ? sysDepartParam.getAddress() : caseMainDetailInfo.getFastContactAddress());
            fastCaseAddInfoDto.setStatementPleadTerm(ObjectUtil.isEmpty(caseMainDetailInfo.getStatementPleadTerm()) ? Constant.STRING_3 : caseMainDetailInfo.getStatementPleadTerm());
            fastCaseAddInfoDto.setPartyOpinion(ObjectUtil.isEmpty(caseMainDetailInfo.getPartyOpinion()) ? "" : caseMainDetailInfo.getPartyOpinion());
            if (ObjectUtil.isEmpty(caseMainDetailInfo.getRelateEvidence())) {
                List<String> evidenceCollectInfoNameList = this.getEvidenceCollectInfoNameList(caseId);
                fastCaseAddInfoDto.setRelateEvidence(StringUtils.join(evidenceCollectInfoNameList, ","));
            }
        }
        fastCaseAddInfoDto.setPartyName(casePartiesInfo.getPartyName());
        fastCaseAddInfoDto.setCaseHappenTime(caseHappenTime);
        fastCaseAddInfoDto.setCaseHappenAddressDetail(caseMainDetailInfo.getCaseHappenAddressDetail());
        fastCaseAddInfoDto.setCaseReasonName(caseReasonMainRecordVo.getCaseReasonName());
        fastCaseAddInfoDto.setCaseReasonNameSimple(caseReasonMainRecordVo.getCaseReasonNameSimple());
        fastCaseAddInfoDto.setCaseOrgCode(caseMainInfo.getCaseOrgCode());
        fastCaseAddInfoDto.setListCode(listCode);
        return fastCaseAddInfoDto;
    }


    private List<FastCaseEvidenceDocumentDto> assembleRelateDocumentInfoList(List<CaseRelateDocumentInfoDto> dtoList,ConfigFastProcedureDocumentInfoVo documentInfoVo) {
        List<FastCaseEvidenceDocumentDto> relateDocumentInfoList = new ArrayList<>();
        if (null != dtoList && dtoList.size() > 0) {
            for (CaseRelateDocumentInfoDto dto : dtoList) {
                FastCaseEvidenceDocumentDto documentDto = new FastCaseEvidenceDocumentDto();
                BeanUtils.copyProperties(dto, documentDto);
                documentDto.setDocumentId(dto.getDocumentId());
                documentDto.setFileName(dto.getDocumentNumber());
                documentDto.setFileUrl(dto.getDocumentUrl());
                documentDto.setFileNamePrefix(dto.getDocumentNumber());
                documentDto.setFileNameSuffix(Constant.STRING_PDF_LOWER);
                documentDto.setButtonCode(FastCaseEvidenceCollectOperateButtonEnum.RELATED_DOCUMENT.getCode());
                documentDto.setTemplateSource(FastCaseMattersTemplateSourceEnum.S01.getCode());
                documentDto.setDocumentKindCode(documentInfoVo.getDocumentKindCode());
                relateDocumentInfoList.add(documentDto);
            }
        }
        return relateDocumentInfoList;
    }

    private List<FastCaseEvidenceDocumentDto> assembleOfflineDocumentInfoList(List<CaseOfflineDocumentRecord> dtoList) {
        List<FastCaseEvidenceDocumentDto> relateDocumentInfoList = new ArrayList<>();
        if (null != dtoList && dtoList.size() > 0) {
            for (CaseOfflineDocumentRecord dto : dtoList) {
                FastCaseEvidenceDocumentDto documentDto = new FastCaseEvidenceDocumentDto();
                documentDto.setDocumentId(dto.getId());
                documentDto.setFileName(dto.getAppendixName());
                documentDto.setFileUrl(dto.getDocumentUrl());
                documentDto.setFileNamePrefix(dto.getAppendixNamePrefix());
                documentDto.setFileNameSuffix(dto.getAppendixNameSuffix());
                documentDto.setDocumentKindCode(dto.getDocumentKindCode());
                documentDto.setButtonCode(FastCaseEvidenceCollectOperateButtonEnum.OFFLINE_DOCUMENT.getCode());
                documentDto.setTemplateSource(FastCaseMattersTemplateSourceEnum.S01.getCode());
                relateDocumentInfoList.add(documentDto);
            }
        }
        return relateDocumentInfoList;
    }


    /**
     * 描述：获取证据列表名称
     * aram caseId
     *
     * @return {@link List<String> }
     * @author shishengyao
     * @date 2023/09/06
     */
    @Override
    public List<String> getEvidenceCollectInfoNameList(String caseId) {
        List<String> evidenceNameList = new ArrayList<>();
        //证据材料
        List<Map> caseEvidenceInfoList = evidenceInventoryService.getCaseEvidenceInfoList(caseId);
        if (null != caseEvidenceInfoList && caseEvidenceInfoList.size()>0){
            caseEvidenceInfoList.forEach(e -> {
                evidenceNameList.add(MapUtils.getString(e, "evidenceName", ""));
            });
        }

        List<CaseDocumentRecordDetailVo> caseDocumentRecordDetailVoList = caseDocumentRecordMapper.selectFastCaseEvidenceDocumentList(caseId);
        //文书
        if (null != caseDocumentRecordDetailVoList && caseDocumentRecordDetailVoList.size()>0){
            caseDocumentRecordDetailVoList.forEach(e -> {
                evidenceNameList.add(e.getDocumentCatalogName());
            });
        }
        //关联文书
        List<CaseStageLinkRelateDocumentVo> caseStageLinkRelateDocumentVoList = caseRelatedDocumentRecordService.getRelatedDocInfoToCaseStageLinkRelateDocument(caseId);
        if (null != caseStageLinkRelateDocumentVoList && caseStageLinkRelateDocumentVoList.size()>0){
            caseStageLinkRelateDocumentVoList.forEach(e -> {
                evidenceNameList.add(e.getDocumentCatalogName());
            });
        }
        //上传线下文书
        List<CaseStageLinkRelateDocumentVo> offlineDocInfoList = caseOfflineDocumentRecordService.getOfflineDocInfoToCaseStageLinkRelateDocument(caseId);
        if (null != offlineDocInfoList && offlineDocInfoList.size()>0){
            offlineDocInfoList.forEach(e -> {
                evidenceNameList.add(e.getDocumentTitle());
            });
        }
        return evidenceNameList;
    }

    @Override
    public Boolean delEvidenceCollectInfo(FastCaseEvidenceCollectInfoDeleteDto dto) {
        //1、删除在线制作文书
        if (FastCaseEvidenceCollectOperateButtonEnum.ONLINE_DOCUMENT.getCode().equals(dto.getButtonCode())){
            //1、删除证据
            if (FastCaseMattersTemplateSourceEnum.S02.getCode().equals(dto.getTemplateSource()) ){
                if ( ObjectUtil.isEmpty(dto.getEvidenceUid())){
                    throw new BusinessException("删除证据时，证据id不能为空");
                }
                EvidenceDetailQueryDto queryDto = new EvidenceDetailQueryDto();
                queryDto.setUid(dto.getEvidenceUid());
                queryDto.setCaseId(dto.getCaseId());
                //证据删除
                return  evidenceInventoryService.removeEvidenceByUid(queryDto);
            }else {
                //没有线上文书，删除
                CaseDocumentRecord caseDocumentRecord = caseDocumentRecordMapper.selectByPrimaryKey(dto.getDocumentId());
                CaseDocumentRecordDelRequest caseDocumentRecordDelRequest = new CaseDocumentRecordDelRequest();
                caseDocumentRecordDelRequest.setDocumentCatalogCode(caseDocumentRecord.getDocumentCatalogCode());
                caseDocumentRecordDelRequest.setPartyId(caseDocumentRecord.getPartyId());
                caseDocumentRecordDelRequest.setDocumentId(dto.getDocumentId());
                caseDocumentRecordDelRequest.setCaseId(dto.getCaseId());
                int i = caseDocumentRecordService.delCaseDocumentRecordInfo(caseDocumentRecordDelRequest);
                if (i>0){
                    return true;
                }
            }
        }
        //3、删除上传线下文书
        if (FastCaseEvidenceCollectOperateButtonEnum.OFFLINE_DOCUMENT.getCode().equals(dto.getButtonCode())){
            Example exampleOffline = new Example(CaseOfflineDocumentRecord.class);
            //清理之前保存的线下文书
            exampleOffline.createCriteria().andEqualTo("documentKindCode", dto.getDocumentKindCode())
                    .andEqualTo("caseId", dto.getCaseId())
                    .andEqualTo("id",dto.getDocumentId())
                    .andEqualTo("status", "1");
            int i =  caseOfflineDocumentRecordMapper.deleteByExample(exampleOffline);
            if (i>0){
                return true;
            }
        }
        //4、删除关联文书
        if (FastCaseEvidenceCollectOperateButtonEnum.RELATED_DOCUMENT.getCode().equals(dto.getButtonCode())){
            //清理之前的关联文书
            caseRelatedDocumentRecordService.delFastCaseRelatedDocument(dto.getCaseId(), Constant.STRING_1, dto.getDocumentKindCode(),dto.getDocumentId());
            return  true;
        }
        return false;
    }


    /**
     * @param dtoList
     * @return {@link List<FastCaseEvidenceOnlineDocumentDto> }
     * @author shishengyao
     * @date 2023/09/06
     */
    private List<FastCaseEvidenceOnlineDocumentDto> assembleDocumentRecordList(List<CaseDocumentRecordDto> dtoList) {
        List<FastCaseEvidenceOnlineDocumentDto> relateDocumentInfoList = new ArrayList<>();
        if (null != dtoList && dtoList.size() > 0) {
            for (CaseDocumentRecordDto dto : dtoList) {
                FastCaseEvidenceOnlineDocumentDto documentDto = new FastCaseEvidenceOnlineDocumentDto();
                BeanUtils.copyProperties(dto, documentDto);
                documentDto.setDocumentId(dto.getId());
                documentDto.setFileName(dto.getDocumentKindName());
                documentDto.setFileUrl(dto.getDocumentUrl());
                documentDto.setFileNamePrefix(dto.getDocumentKindName());
                documentDto.setFileNameSuffix(Constant.STRING_PDF_LOWER);
                documentDto.setButtonCode(FastCaseEvidenceCollectOperateButtonEnum.ONLINE_DOCUMENT.getCode());
                documentDto.setTemplateSource(FastCaseMattersTemplateSourceEnum.S01.getCode());
                relateDocumentInfoList.add(documentDto);
            }
        }
        return relateDocumentInfoList;
    }

    /**
     * 描述：组装证据端地址
     *
     * @param caseEvidenceInfoList
     * @return {@link List<FastCaseEvidenceOnlineDocumentDto> }
     * @author shishengyao
     * @date 2023/09/05
     */
    private List<FastCaseEvidenceOnlineDocumentDto> assembleEvidenceDocumentRecordList(List<Map> caseEvidenceInfoList, ConfigFastProcedureDocumentInfoVo documentInfoVo) {
        List<FastCaseEvidenceOnlineDocumentDto> relateDocumentInfoList = new ArrayList<>();
        if (null != caseEvidenceInfoList && caseEvidenceInfoList.size() > 0) {
            for (Map dto : caseEvidenceInfoList) {
                String evidenceType = MapUtils.getString(dto, "evidenceType", "");
                if (evidenceType.equals(EvidenceOperateTypeEnum.getCodeeByDocumentKindCode(documentInfoVo.getDocumentKindCode()))) {
                    FastCaseEvidenceOnlineDocumentDto documentDto = new FastCaseEvidenceOnlineDocumentDto();
                    documentDto.setDocumentId(MapUtils.getString(dto, "evidenceUid", ""));
                    //
                    documentDto.setEvidenceUid(MapUtils.getString(dto, "circulationUid", ""));
                    documentDto.setFileName(MapUtils.getString(dto, "evidenceName", ""));
                    documentDto.setLinkType(MapUtils.getString(dto, "linkType", ""));
                    documentDto.setDocumentKindCode(documentInfoVo.getDocumentKindCode());
                    documentDto.setDocumentKindName(documentInfoVo.getDocumentKindName());
                    documentDto.setButtonCode(FastCaseEvidenceCollectOperateButtonEnum.ONLINE_DOCUMENT.getCode());
                    documentDto.setTemplateSource(FastCaseMattersTemplateSourceEnum.S02.getCode());
                    relateDocumentInfoList.add(documentDto);
                }
            }
        }
        return relateDocumentInfoList;
    }

    /**
     * 描述：保存线下文书
     *
     * @param caseMainInfo     案件详情
     * @param userInfo         用户信息
     * @param evidenceDetailVo 证据细节签证官
     * @author shishengyao
     * @date 2023/08/21
     */
    private void saveOfflineDocument(CaseMainInfoVo caseMainInfo, UserDTO userInfo, FastCaseEvidenceDetailDto evidenceDetailVo, ConfigFastProcedureDocumentInfoVo documentInfoVo) {
        Example exampleOffline = new Example(CaseOfflineDocumentRecord.class);
        //清理之前保存的线下文书
        exampleOffline.createCriteria().andEqualTo("documentKindCode", documentInfoVo.getDocumentKindCode())
                .andEqualTo("caseId", caseMainInfo.getId())
                .andEqualTo("status", "1");
        caseOfflineDocumentRecordMapper.deleteByExample(exampleOffline);
        List<FastCaseEvidenceDocumentDto> offlineDocumentSaveDtoList = evidenceDetailVo.getCaseOfflineDocumentInfoList();
        if (ObjectUtil.isNotEmpty(offlineDocumentSaveDtoList)) {
            for (FastCaseEvidenceDocumentDto caseEvidenceDocumentDto : offlineDocumentSaveDtoList) {
                ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = configBusiParamDocumentInfoService.getDocumentInfoByDocumentKindCode(caseMainInfo.getBusiParamId(), DocumentKindEnum.DOC_KIND_ZLGZTZS.getCode());
                CaseOfflineDocumentRecord offlineDocumentRecord = new CaseOfflineDocumentRecord();
                BeanUtils.copyProperties(caseEvidenceDocumentDto, offlineDocumentRecord);
                offlineDocumentRecord.setAppendixName(caseEvidenceDocumentDto.getFileName());
                offlineDocumentRecord.setAppendixNamePrefix(caseEvidenceDocumentDto.getFileNamePrefix());
                offlineDocumentRecord.setAppendixNameSuffix(caseEvidenceDocumentDto.getFileNameSuffix());
                offlineDocumentRecord.setDocumentUrl(caseEvidenceDocumentDto.getFileUrl());
                offlineDocumentRecord.setDocumentCatalogCode(documentInfoVo.getDocumentCatalogCode());
                offlineDocumentRecord.setCaseId(caseMainInfo.getId());
                offlineDocumentRecord.setDocumentKindCode(documentInfoVo.getDocumentKindCode());
                offlineDocumentRecord.setDocumentKindName(documentInfoVo.getDocumentKindName());
                offlineDocumentRecord.setDocumentType(configBusiParamDocumentInfo.getDocumentType());
                offlineDocumentRecord.setDocumentDesc(evidenceDetailVo.getDocumentCatalogName());
                offlineDocumentRecord.setDocumentTittle(caseEvidenceDocumentDto.getFileNamePrefix());
                offlineDocumentRecord.setCaseLinkCode(caseMainInfo.getCaseCurrentLinkCode());
                offlineDocumentRecord.setCaseLinkName(caseMainInfo.getCaseCurrentLinkName());
                offlineDocumentRecord.setCaseStageCode(caseMainInfo.getCaseCurrentStageCode());
                offlineDocumentRecord.setCaseStageName(caseMainInfo.getCaseCurrentStageName());
                offlineDocumentRecord.setCreateUserId(userInfo.getUserId().toString());
                offlineDocumentRecord.setCreateUserName(userInfo.getRealName());
                offlineDocumentRecord.setStatus(Constant.STRING_1);
                offlineDocumentRecord.setId(StringUtils.uuid());
                offlineDocumentRecord.setCreateTime(LocalDateTime.now());
                caseOfflineDocumentRecordMapper.insertSelective(offlineDocumentRecord);
            }

        }
    }

    /**
     * 保存关联文书
     *
     * @param caseMainInfo     案件信息
     * @param userInfo         用户信息
     * @param evidenceDetailVo 证据细节签证官
     * @author shishengyao
     * @date 2023/08/21
     */
    private void saveRelateDocumentInfo(CaseMainInfoVo caseMainInfo, UserDTO userInfo, FastCaseEvidenceDetailDto evidenceDetailVo, CasePartiesRecordVo casePartiesInfo, ConfigFastProcedureDocumentInfoVo documentInfoVo) {
        String caseId = caseMainInfo.getId();
        //清理之前的关联文书
        caseRelatedDocumentRecordService.delFastCaseRelatedDocument(caseId, Constant.STRING_1, documentInfoVo.getDocumentKindCode(),null);
        List<FastCaseEvidenceDocumentDto> relateDocumentInfoDtoList = evidenceDetailVo.getCaseRelateDocumentInfoList();
        if (ObjectUtil.isNotEmpty(relateDocumentInfoDtoList)) {
            CaseRelatedDocumentSaveDto saveDto = new CaseRelatedDocumentSaveDto();
            saveDto.setCaseId(caseId);
            List<CaseRelateDocumentInfoDto> caseRelatedDocumentRecordList = new ArrayList<>();
            for (FastCaseEvidenceDocumentDto relateDocumentInfoDto : relateDocumentInfoDtoList) {
                //查询关联的文书是否存在
                CaseRelatedAppDocumentVo caseRelatedAppDocumentVo = caseRelatedDocumentRecordMapper.selectCaseRelateDocumentInfoDtoByDocumentId(relateDocumentInfoDto.getDocumentId());
                if (ObjectUtils.isEmpty(caseRelatedAppDocumentVo)) {
                    throw new BusinessException("要关联的文书不存在");
                }
                if (!caseRelatedAppDocumentVo.getPartyIdentityCode().equals(casePartiesInfo.getPartyIdentityCode())) {
                    throw new BusinessException("关联的文书不是当前当事人的文书");
                }
                CaseRelateDocumentInfoDto record = new CaseRelateDocumentInfoDto();
                record.setDocumentCatalogCode(caseRelatedAppDocumentVo.getDocumentCatalogCode());
                record.setDocumentCatalogName(caseRelatedAppDocumentVo.getDocumentCatalogName());
                record.setDocumentId(caseRelatedAppDocumentVo.getDocumentId());
                record.setDocumentNumber(caseRelatedAppDocumentVo.getDocumentNumber());
                record.setDocumentUrl(caseRelatedAppDocumentVo.getDocumentUrl());
                record.setDocumentType(caseRelatedAppDocumentVo.getDocumentType());
                record.setPartyIdentityCode(caseRelatedAppDocumentVo.getPartyIdentityCode());
                record.setPartyIdentityType(caseRelatedAppDocumentVo.getPartyIdentityType());
                record.setRelatedType(Constant.STRING_1);
                // 查询业务关联文书配置
                record.setPartyType(caseRelatedAppDocumentVo.getPartyType());
                caseRelatedDocumentRecordList.add(record);
            }
            saveDto.setRelatedDocumentList(caseRelatedDocumentRecordList);
            caseRelatedDocumentRecordService.saveCaseRelatedDocument(saveDto);

        }
    }

    /**
     * 描述：校验线上制作文书是否存在
     *
     * @param evidenceDocumentDtoList 证据文档dto列表
     * @author shishengyao
     * @date 2023/08/21
     */
    private void checkOnlineDocument(List<FastCaseEvidenceOnlineDocumentDto> evidenceDocumentDtoList, FastCaseEvidenceDetailDto evidenceDetailVo, CasePartiesRecordVo partiesRecordVo, ConfigFastProcedureDocumentInfoVo documentInfoVo) {
        if (ObjectUtil.isNotEmpty(evidenceDocumentDtoList)) {
            for (FastCaseEvidenceOnlineDocumentDto documentDto : evidenceDocumentDtoList) {
                CaseDocumentRecordVo caseDocumentRecordInfo = caseDocumentRecordService.getCaseDocumentRecordInfo(documentDto.getDocumentId());
                if (ObjectUtils.isEmpty(caseDocumentRecordInfo)) {
                    throw new BusinessException("在线制作的文书不存在");
                }
                if (Constant.STRING_1.equals(documentInfoVo.getIsConfirm()) && !DocumentStatusEnum.CONFIRM_END.getCode().equals(caseDocumentRecordInfo.getDocumentSignstampedStatus())) {
                    throw new BusinessException("在线制作的文书未确认");
                }
            }
        } else {
            //没有线上文书，删除
            CaseDocumentRecordDelRequest caseDocumentRecordDelRequest = new CaseDocumentRecordDelRequest();
            caseDocumentRecordDelRequest.setDocumentCatalogCode(evidenceDetailVo.getDocumentCatalogCode());
            caseDocumentRecordDelRequest.setPartyId(partiesRecordVo.getPartyId());
            caseDocumentRecordDelRequest.setCaseId(partiesRecordVo.getCaseId());
            int i = caseDocumentRecordService.delCaseDocumentRecordInfo(caseDocumentRecordDelRequest);
        }
    }

    /**
     * 描述：删除线上文书
     *
     * @param evidenceDocumentDtoList 证据文档dto列表
     * @author shishengyao
     * @date 2023/08/21
     */
    private void dealOnlineDocument(List<FastCaseEvidenceOnlineDocumentDto> evidenceDocumentDtoList, FastCaseEvidenceDetailDto evidenceDetailVo, CasePartiesRecordVo partiesRecordVo, ConfigFastProcedureDocumentInfoVo documentInfoVo) {
        if (ObjectUtil.isEmpty(evidenceDocumentDtoList) && ObjectUtil.isNotEmpty(documentInfoVo.getDocumentCatalogCode())) {
            //没有线上文书，删除
            CaseDocumentRecordDelRequest caseDocumentRecordDelRequest = new CaseDocumentRecordDelRequest();
            caseDocumentRecordDelRequest.setDocumentCatalogCode(documentInfoVo.getDocumentCatalogCode());
            caseDocumentRecordDelRequest.setPartyId(partiesRecordVo.getPartyId());
            caseDocumentRecordDelRequest.setCaseId(partiesRecordVo.getCaseId());
            int i = caseDocumentRecordService.delCaseDocumentRecordInfo(caseDocumentRecordDelRequest);
        }
    }

    /**
     * 描述：删除单个证据
     *
     * @param removeEvidenceUids
     * @param caseId
     * @author shishengyao
     * @date 2023/09/05
     */
    public void removeEvidenceByUids(List<String> removeEvidenceUids, String caseId) {
        if (ObjectUtil.isNotEmpty(removeEvidenceUids) && removeEvidenceUids.size() > 0) {
            for (String evidenceUid : removeEvidenceUids) {
                EvidenceDetailQueryDto queryDto = new EvidenceDetailQueryDto();
                queryDto.setUid(evidenceUid);
                queryDto.setCaseId(caseId);
                evidenceInventoryService.removeEvidenceByUid(queryDto);
            }
        }
    }
}
